package com.whpost.service.dao.stamp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.whpost.service.entity.stamp.Dhm;
import com.whpost.service.entity.stamp.StampCardOrder;
import com.whpost.service.entity.stamp.StampHdDhm;
import com.whpost.service.entity.stamp.StampHdDhmMx;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author YinZhuoyi
 * @since 2025-11-03
 */
public interface StampHdDhmMapper extends BaseMapper<StampHdDhm> {

    @Select("select * from stamp_hd_dhm where id=#{0}")
    @Results(id="hdDhmMap",value = {
            @Result(column="xm_id",property="stampXm",
                    one=@One(
                            select="com.whpost.service.dao.stamp.StampXmMapper.selectById")
            ),
            @Result(column="xm_id",property="xmId"),
            @Result(column="hd_id",property="stampHd",
                    one=@One(
                            select="com.whpost.service.dao.stamp.StampHdMapper.getById")
            ),
            @Result(column="hd_id",property="hdId")
    })
    StampHdDhm getById(Long id);

    @Select("select * from stamp_hd_dhm where ${ew.sqlSegment} ")
    @ResultMap(value="hdDhmMap")
    IPage<StampHdDhm> getStampHdDhmLPage(Page<StampHdDhm> page, @Param("ew") QueryWrapper wrapper);

    @Select("select (select name from stamp_xm where id=STAMP_HD_DHM_MX.xm_id) as xm,(select name from stamp_hd where id=STAMP_HD_DHM_MX.hd_id) as hd,dhm,sybz as sfsy,order_id as gldd from STAMP_HD_DHM_MX where zb_id=#{zbid}")
    List<Dhm> getDhm(@Param("zbid") String zbid);

    @Update("update stamp_hd_dhm_mx set sybz='1',order_id=#{order_id} where xm_id=#{xm_id} and hd_id=#{hd_id} and dhm=#{dhm} and sybz=0")
    int payByDhm(@Param("xm_id") Long xm_id,@Param("hd_id") Long hd_id,@Param("dhm") String dhm,@Param("order_id") Long order_id);

}
